const Util = {
  prepareBankCards: cards => {
    let len = cards.length
    if (len === 0) {
      return []
    }
    for (let i = 0, l = len; i < l; i++) {
      let bankName = cards[i]['bank'].replace('中国', '')
      cards[i]['bankNameCardNo'] = bankName + '（' + cards[i]['cardNo'] + '）'
    }
    return cards
  },
  /* eslint-disable */
  msg: (msg, callback) => {
    let opts = {
      content: msg,
      skin: 'msg',
      time: 2,
    }
    if (typeof callback === 'function') {
      opts.end = function () {
        callback()
      }
    }
    layer.open(opts)
  },
  handleResponse: (resp, successMsg, successCallback, errorMsg = '') => {
    successMsg = successMsg ? successMsg : '操作成功'
    let successCode = 1
    if (parseInt(resp.code) === successCode) {
      Util.msg(successMsg, successCallback)
    } else {
      errorMsg = errorMsg ? errorMsg : resp.msg
      Util.msg(errorMsg)
    }
  }
}

export default Util
